package com.dqhl.community.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dqhl.community.R;
import com.dqhl.community.base.BaseActivity;
import com.dqhl.community.util.Config;
import com.dqhl.community.util.Constant;
import com.dqhl.community.util.Dlog;
import com.dqhl.community.util.JsonUtils;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

/**
 * Created by cheng on 2016/9/11.
 * 预约记录
 */
public class OrderedRecordActivity extends BaseActivity implements View.OnClickListener {

    private ImageView ivTopBack;
    private TextView tvTopTitle;
    private LinearLayout ll_appliance_clean; //家电清洗预约记录
    private LinearLayout ll_appliance_repair; //家电维修预约
    private LinearLayout ll_housekeeping; //家政服务预约
    private LinearLayout ll_chat; //医疗服务预约

    private TextView tv_appliance_clean_number;
    private TextView tv_appliance_repair_number;
    private TextView tv_housekeeping_number;
    private TextView tv_chat_number;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ordered_record);

        initView();

        getRecordNumber();
    }

    private void getRecordNumber() {
        RequestParams params = new RequestParams(Config.Api.orderedRecordNumber);
        params.addBodyParameter("userid", spUserInfo.getString(Constant.USERID, ""));
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                Dlog.e(result);
                int errCode = JsonUtils.getErrCode(result);
                String data = JsonUtils.getInfo(result, "data");
                Dlog.e("data:" + data);
                if (errCode == 0) {
                    String cleanNumber = JsonUtils.getInfo(data, "clean");
                    String repairNumber = JsonUtils.getInfo(data, "service");
                    String housekeepingNumber = JsonUtils.getInfo(data, "housekeeping");
                    String chatNumber = JsonUtils.getInfo(data, "hospitalReady");
                    tv_appliance_clean_number.setText(cleanNumber);
                    tv_appliance_repair_number.setText(repairNumber);
                    tv_housekeeping_number.setText(housekeepingNumber);
                    tv_chat_number.setText(chatNumber);
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    private void initView() {
        ivTopBack = (ImageView) findViewById(R.id.iv_top_back);
        ivTopBack.setVisibility(View.VISIBLE);
        tvTopTitle = (TextView) findViewById(R.id.tv_top_title);
        tvTopTitle.setText("预约记录");
        ll_appliance_clean = (LinearLayout) findViewById(R.id.ll_appliance_clean);
        ll_appliance_repair = (LinearLayout) findViewById(R.id.ll_appliance_repair);
        ll_housekeeping = (LinearLayout) findViewById(R.id.ll_housekeeping);
        ll_chat = (LinearLayout) findViewById(R.id.ll_health_chat);

        tv_appliance_clean_number = (TextView) findViewById(R.id.tv_appliance_clean_number);
        tv_appliance_repair_number = (TextView) findViewById(R.id.tv_appliance_repair_number);
        tv_housekeeping_number = (TextView) findViewById(R.id.tv_housekeeping_number);
        tv_chat_number = (TextView) findViewById(R.id.tv_chat_number);

        ivTopBack.setOnClickListener(this);
        ll_appliance_clean.setOnClickListener(this);
        ll_appliance_repair.setOnClickListener(this);
        ll_housekeeping.setOnClickListener(this);
        ll_chat.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_top_back:
                finish();
                break;
            case R.id.ll_appliance_clean: //家电清洗
                overlay(ApplianceCleanRecordActivity.class);
                break;
            case R.id.ll_appliance_repair://家电维修
                overlay(ApplianceRepairRecordActivity.class);
                break;
            case R.id.ll_housekeeping://家政服务
                overlay(FamilyServiceRecordActivity.class);
                break;
            case R.id.ll_health_chat://医疗服务
                overlay(CommunityHealthRecordActivity.class);
                break;
        }
    }
}
